<?php

declare(strict_types=1);

namespace App\Robot\Job;

use App\CustHub\Mapper\ChRobotMapper;
use App\CustHub\Service\ChRobotService;
use App\CustHub\Service\LicenseService;
use Hyperf\AsyncQueue\Job;

class UserIdToOpenIdTaskJob extends Job
{
    public int $robotId;

    public mixed $changeId;

    public bool $isRobot;

    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     */
    protected int $maxAttempts = 2;


    public function __construct(int $robotId, mixed $changeId, bool $isRobot = true)
    {
        $this->robotId = $robotId;
        $this->changeId = $changeId;
        $this->isRobot = $isRobot;
    }

    public function handle(): void
    {
        $robotMapper = container()->get(ChRobotMapper::class);
        $open_user_id = container()->get(ChRobotService::class)->getOpenid($this->robotId);
        if(!empty($open_user_id)){
            //绑定席位处理
            $robotInfo = $robotMapper->findById($this->robotId);
            container()->get(LicenseService::class)->robotAutoBindHtSeat($robotInfo,$open_user_id);
        }
    }
}